//
//  ETArrayReformer.m
//  PywSdk
//
//  Created by liangyidong on 16/3/4.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "ETArrayReformer.h"
#import "AIFGetCouponManager.h"
#import "AIFGetAccountListManager.h"
#import "PywCoupon.h"
#import "PywAccount.h"

@implementation ETArrayReformer

- (NSArray *)manager:(ETApiBaseManager *)manager reformData:(id)data{
    NSArray *resultArray = nil;
    NSDictionary *resultData = nil;
    NSData * decodeResponse = [AppUtil decode:data];
    resultData = [NSJSONSerialization JSONObjectWithData:decodeResponse options:NSJSONReadingMutableContainers error:nil];
    NSArray *tmpDictArray = resultData[@"data"];
    
    // 代金券列表
    if ([manager isKindOfClass:[AIFGetCouponManager class]]) {
        NSMutableArray *tmpCouponsArray = [NSMutableArray array];
        for (NSDictionary *dict in tmpDictArray) {
            if (![dict isKindOfClass:[NSDictionary class]]) continue;
            PywCoupon *coupon = [PywCoupon couponWithDict:dict type:@"unuse"];
            if (coupon == nil) continue;
            [tmpCouponsArray addObject:coupon];
        }
        resultArray = tmpCouponsArray;
    }
    
//    用户列表
    if ([manager isKindOfClass:[AIFGetAccountListManager class]]){
        NSMutableArray *tmpArray = [NSMutableArray array];
        for (NSDictionary *dict in tmpDictArray) {
            if (![dict isKindOfClass:[NSDictionary class]]) continue;
            PywAccount *account = [PywAccount accountWithDict:dict];
            if (account == nil) continue;
            [tmpArray addObject:account];
        }
        resultArray = tmpArray;
    }
    
    return resultArray;
}

@end
